protected bool Shooting;
protected int ShotCooldown;
- public MainShip(Game newGame) : base(newGame) {}
+ protected float CurrentImmortalTime;
+ protected float MaxImmortalTime;
+ protected bool Flashing;
+
+ public MainShip(SuperPolarity newGame) : base(newGame) {}
~MainShip()
{
SetPolarity(Polarity.Positive);
ShotCooldown = 50;
+ MaxImmortalTime = 1500;
+
+ BoxDimensions.X = 2;
+ BoxDimensions.Y = 2;
+ BoxDimensions.W = 2;
+ BoxDimensions.Z = 2;
+ InitBox();
BindInput();
}
protected void HandleShot(float value)
{
- Children.Add(ActorFactory.CreateBullet(Position, Angle));
+ var bullet = ActorFactory.CreateBullet(Position, Angle);
+
+ Children.Add(bullet);
+ bullet.Parent = this;
+
Shooting = true;
Timer t = new Timer(new TimerCallback(UnlockShot));
t.Change(ShotCooldown, Timeout.Infinite);
{
base.SwitchPolarity();
SwitchParticleEngine(CurrentPolarity);
+ game.Player.ResetMultiplier();
}
public override void SetPolarity(Polarity newPolarity)
particleEngine.EmitterLocation = Position;
particleEngine.Update();
ConstrainToEdges();
+ UpdateImmortality(gameTime);
Shooting = false;
}
+ public void UpdateImmortality(GameTime gameTime)
+ {
+ if (Immortal)
+ {
+ CurrentImmortalTime += gameTime.ElapsedGameTime.Milliseconds;
+
+ if (Flashing)
+ {
+ Color = new Color(255, 255, 255, 128);
+ }
+ else
+ {
+ Color = Color.White;
+ }
+
+ Flashing = !Flashing;
+
+ if (CurrentImmortalTime > MaxImmortalTime)
+ {
+ Immortal = false;
+ Color = Color.White;
+ }
+ }
+ }
+
public override void Move(GameTime gameTime)
{
base.Move(gameTime);
particleEngine.Draw(spriteBatch);
base.Draw(spriteBatch);
}
+
+ public override void Collide(Actor other, Rectangle collision)
+ {
+ if (other.GetType().IsAssignableFrom(typeof(StandardShip)) &&
+ !Immortal)
+ {
+ Die();
+ }
+ }
+
+ protected override void Die()
+ {
+ game.Player.Lives = game.Player.Lives - 1;
+ game.Player.ResetMultiplier();
+ if (game.Player.Lives < 0)
+ {
+ Dying = true;
+ }
+ else {
+ Immortal = true;
+ CurrentImmortalTime = 0;
+ }
+ }
}
}